package cn.edu.hbsi.web.controller;

import cn.edu.hbsi.domain.result.Result;
import cn.edu.hbsi.domain.result.ResultCodeEnum;
import cn.edu.hbsi.service.UserService;
import cn.edu.hbsi.utils.JwtHelper;
import com.alibaba.druid.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通用模块
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "通用模块相关接口")
public class AdminController
{
    @Autowired
    private UserService userService;

    @Autowired
    private JwtHelper jwtHelper;

    /**
     * 登录验证和保护功能
     * @param token
     * @return
     */
    @GetMapping("/checkLogin")
    @ApiOperation("登录验证和保护功能")
    public Result checkLogin(@RequestHeader String token){
        if (StringUtils.isEmpty(token) || jwtHelper.isExpiration(token)){
            //没有传或者过期 未登录
            return Result.build(null, ResultCodeEnum.NOTLOGIN);
        }
        return Result.ok(null);
    }
}
